package com.springboot.study.tests;

/**
 * @Author: guodong
 * @Date: 2021/2/21 11:07
 * @Version: 1.0
 * @Description:
 */
public class UnsafeLazyInitialization {

    private static volatile UnsafeLazyInitialization instance;

    public static synchronized UnsafeLazyInitialization getInstance() {
        if(instance == null)  // 4:第一次检查
            synchronized (UnsafeLazyInitialization.class){ //5:加锁
                if(instance == null ){ // 6:第二次检查
                    instance = new UnsafeLazyInitialization(); //7:问题的根源出在这里
                }
            }
        return instance;
    }

}
